package cn.btks.resultintegration.achievements.controller;

import cn.btks.commonserver.result.MenuSourceEnum;
import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.SystemLogEnum;
import cn.btks.commonserver.valid.SystemLog;
import cn.btks.resultintegration.achievements.pojo.Achievements;
import cn.btks.resultintegration.achievements.pojo.AchievementsTemp;
import cn.btks.resultintegration.achievements.service.AchievementsTempService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

/**
 * @Author lijun
 * @Date 2021/2/22 10:45
 */
@Slf4j
@RestController
@RequestMapping("api/v1.0/resultIntegration/achievements/temp")
@Api(tags = "成果整合模块")
@Validated
public class AchievementsTempController {

    @Autowired
    AchievementsTempService achievementsTempService;

    @SystemLog(type = SystemLogEnum.QUERY_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @GetMapping("/report/findPages")
    @ApiOperation("分页查询师级审核成果数据-上报查询")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNumber", value = "当前页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页行数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "isApproved", value = "0：审核不通过 1：审核通过 2：审核中", required = false, dataType = "int"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState findReportPages(Integer pageNumber, Integer pageSize, Integer isApproved) {
        return achievementsTempService.findPage(pageNumber, pageSize, isApproved);
    }

    @SystemLog(type = SystemLogEnum.QUERY_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @GetMapping("/report/findPages1")
    @ApiOperation("兵团根据师级区划ID查询师级审核通过数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNumber", value = "当前页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页行数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "cityId", value = "师级区划ID", required = true, dataType = "int"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState findReportPages1(Integer pageNumber, Integer pageSize, Long cityId) {
        return achievementsTempService.findPage2(pageNumber, pageSize, cityId);
    }

    @SystemLog(type = SystemLogEnum.QUERY_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @GetMapping("/verifying/findPages")
    @ApiOperation("分页查询师级审核成果数据-待审核查询")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNumber", value = "当前页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页行数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "isApproved", value = "0：审核不通过 1：审核通过 2：审核中", required = false, dataType = "int"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState findVerifyingPages(Integer pageNumber, Integer pageSize, Integer isApproved) {
        return achievementsTempService.findPage(pageNumber, pageSize, isApproved);
    }

    @SystemLog(type = SystemLogEnum.QUERY_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @GetMapping("/verified/findPages")
    @ApiOperation("分页查询师级审核成果数据-审核成果查询")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNumber", value = "当前页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页行数", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "isApproved", value = "0：审核不通过 1：审核通过 2：审核中", required = false, dataType = "int"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState findVerifiedPages(Integer pageNumber, Integer pageSize, Integer isApproved) {
        return achievementsTempService.findPage(pageNumber, pageSize, isApproved);
    }

    @SystemLog(type = SystemLogEnum.VERIFY_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @PostMapping(value = "/fill/save",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "师级系统审核接口", notes = "师级系统审核接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "content", value = "矢量数据（JSON对象）", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "catalogId", value = "所在目录ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "query", name = "typeId", value = "成果类型ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "query", name = "isApproved", value = "是否审核通过（0：审核不通过 1：审核通过 2：审核中）", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "verifyType", value = "审核方式（0：系统审核 1：人工审核）", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "verifyContent", value = "系统审核内容", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "uploadDate", value = "上传时间", required = true, dataType = "date"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState save(AchievementsTemp achievementsTemp, @ApiParam(value = "multipartTextFile", required = true) MultipartFile multipartTextFile,@ApiParam(name = "多文件", value = "multipartVectorFiles", required = true) MultipartHttpServletRequest multipartVectorFiles,@ApiParam(value = "multipartEvidenceFile", required = true) MultipartHttpServletRequest multipartEvidenceFile, HttpServletRequest request) throws Exception {
        MultiValueMap<String, MultipartFile> mapVector = multipartVectorFiles.getMultiFileMap();
        List<MultipartFile> listVector = mapVector.get("multipartVectorFiles");// 获取到文件的列表
        MultiValueMap<String, MultipartFile> map = multipartEvidenceFile.getMultiFileMap();
        List<MultipartFile> listEvidence = map.get("multipartEvidenceFile");// 获取到文件的列表
        return achievementsTempService.save(achievementsTemp,multipartTextFile,listVector,listEvidence,request);
    }

    @SystemLog(type = SystemLogEnum.UPDATE_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @PostMapping(value = "/fill/update",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "师级系统审核接口-更新", notes = "师级系统审核接口-更新")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "content", value = "矢量数据（JSON对象）", required = false, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "catalogId", value = "所在目录ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "query", name = "typeId", value = "成果类型ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "query", name = "isApproved", value = "是否审核通过（0：审核不通过 1：审核通过 2：审核中）", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "verifyType", value = "审核方式（0：系统审核 1：人工审核）", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "verifyContent", value = "系统审核内容", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "uploadDate", value = "上传时间", required = true, dataType = "date"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState update(AchievementsTemp achievementsTemp, @ApiParam(value = "multipartTextFile", required = true) MultipartFile multipartTextFile,@ApiParam(name = "多文件", value = "multipartVectorFiles", required = true) MultipartHttpServletRequest multipartVectorFiles,@ApiParam(value = "multipartEvidenceFile", required = true) MultipartHttpServletRequest multipartEvidenceFile, HttpServletRequest request) throws Exception {
        MultiValueMap<String, MultipartFile> mapVector = multipartVectorFiles.getMultiFileMap();
        List<MultipartFile> listVector = mapVector.get("multipartVectorFiles");// 获取到文件的列表
        MultiValueMap<String, MultipartFile> map = multipartEvidenceFile.getMultiFileMap();
        List<MultipartFile> listEvidence = map.get("multipartEvidenceFile");// 获取到文件的列表
        return achievementsTempService.update(achievementsTemp,multipartTextFile,listVector,listEvidence,request);
    }

    @SystemLog(type = SystemLogEnum.VERIFY_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @PostMapping(value = "/verify/manualVerify/{isApproved}/{verifyContent}/{achievementTempId}")
    @ApiOperation(value = "师级人工审核接口", notes = "师级人工审核接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "isApproved", value = "是否审核通过（0：审核不通过 1：审核通过 2：审核中）", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "path", name = "verifyContent", value = "审核结果说明", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "path", name = "achievementTempId", value = "成果ID", required = true, dataType = "long"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState manualVerify(@PathVariable("isApproved") Integer isApproved,@PathVariable("verifyContent") String verifyContent,@PathVariable("achievementTempId") Long achievementTempId,HttpServletRequest request) throws Exception {
        return achievementsTempService.manualVerify(isApproved, verifyContent, achievementTempId,request);
    }
}
